package com.jijs.cxf.calc;

import javax.xml.namespace.QName;
import javax.xml.ws.Endpoint;

import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;

public class MyCalcServer {
	
	/**
	 * 普通发布 支持契约优先
	 */
	public static void test1(){
		Endpoint.publish("http://localhost:8080/ms", new CalcWsServiceImpl());
	}
	
	/**
	 * 默认cxf不支持契约优先
	 */
	public static void test2(){
		/**
		 * 通过以下发布的webservice，并不支持契约优先
		 */
		JaxWsServerFactoryBean fac = new JaxWsServerFactoryBean();
		fac.setAddress("http://localhost:8080/ms");
		fac.setServiceClass(ICalcWsService.class);
		fac.setServiceBean(new CalcWsServiceImpl());
		fac.create();
	}
	
	/**
	 * 让cxf支持契约优先发布
	 */
	public static void test3(){
		JaxWsServerFactoryBean fac = new JaxWsServerFactoryBean();
		fac.setAddress("http://localhost:8080/ms");
		fac.setServiceClass(ICalcWsService.class);
		fac.setServiceBean(new CalcWsServiceImpl());
		fac.getInInterceptors().add(new LoggingInInterceptor());
		fac.getOutInterceptors().add(new LoggingOutInterceptor());
		//需要设置以下参数才能支持契约优先发布
		fac.setWsdlLocation("META-INF/wsdl/calc.wsdl");
		fac.setServiceName(new QName("http://cxf.jijs.com/calc/","calcWsService"));
		fac.create();
	}
	
	public static void main(String[] args) {
//		test1();
//		test2();
		test3();
	}
}
